var app = getApp();
var util = require('../../utils/util.js');
var api = require('../../config/api.js');
Page({
  data: {
    id:'',
    content: '',
    index_arr:[0,1,2,3,4],
    ct_arr:['非常差','差','一般','好','非常好'],
    p1:-1,
    p2:-1,
    p3:-1,
    v1:0,
    v2:0,
    v3:0,
    imgs:[]
  },
  onLoad: function (options) {

    var that = this;
    that.setData({id: options.id});

  },
  upload: function () {     
    var that = this;
    var imgs=that.data.imgs;
    wx.showLoading();
    util.upload().then(function (res) 
    {
      if (res.ST == 100) 
      {
        imgs.push(res.Url);
        that.setData({imgs:imgs});
      }
      wx.hideLoading();
    });

  },
  set_point1:function(e){
     var p=e.currentTarget.dataset.index;
     this.setData({p1:p});
  },
  set_point2:function(e){
    var p=e.currentTarget.dataset.index;
    this.setData({p2:p});
 },
 set_point3:function(e){
  var p=e.currentTarget.dataset.index;
  this.setData({p3:p});
},
  onClose() {
    wx.navigateBack({
      delta: 1
    });
  },
  onPost() {
    let that = this;

    if (!this.data.content) {
      util.showErrorToast('请填写评论')
      return false;
    }

    var userInfo=wx.getStorageSync('userInfo');
    var UserID='';
    if(userInfo!="")
    {
      UserID=userInfo.Id;
    }
    var urls="";
    var imgs=that.data.imgs;
    if(imgs.length>0)
    {
      urls=imgs.join(',');
    }
    var pd={
      Point1:that.data.p1,
      Point2:that.data.p2,
      Point3:that.data.p3,
      Summary:that.data.content,
      ImageList:urls,
      Fid:that.data.id,
      UserID:UserID
    };
    util.request(api.CommentPost,pd, 'POST').then(function (res) {
      if (res.Status === 100) {
        wx.showToast({
          title: '评论成功',
          complete: function(){
            wx.navigateBack({
              delta: 1
            });
          }
        })
      }
    });
  },
  bindInpuntValue(event){

    let value = event.detail.value;

    //判断是否超过140个字符
    if (value && value.length > 140) {
      return false;
    }

    this.setData({
      content: event.detail.value,
    })
  },
  onReady: function () {

  },
  onShow: function () {
    // 页面显示

  },
  onHide: function () {
    // 页面隐藏

  },
  onUnload: function () {
    // 页面关闭

  }
})